local ads__shengcai = fk.CreateSkill {
  name = "ads__shengcai",
}

ads__shengcai:addEffect(fk.PreCardUse, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(ads__shengcai.name)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if room:askToSkillInvoke(player, {
      skill_name = ads__shengcai.name,
      prompt = "#ads__shengcai-invoke::"..data.card:toLogString(),
    }) then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = ads__shengcai.name,
      pattern = ".|.|.|.",
      good = true,
    }
    room:judge(judge)
    
    if judge.card then
      if room:askToSkillInvoke(player, {
        skill_name = ads__shengcai.name,
        prompt = "#ads__shengcai-replace",
      }) then
        local originalCardId = data.card.id
        
        data.card = judge.card
        
        if originalCardId and originalCardId ~= judge.card.id then
          room:moveCards({
            ids = { originalCardId },
            from = player,
            toArea = Card.DiscardPile,
            moveReason = fk.ReasonPutIntoDiscardPile,
            skillName = ads__shengcai.name,
          })
        end
        
        room:doAnimate("peach", {
          card = judge.card.id,
          players = {player.id}
        })
      end
    end
  end,
})


Fk:loadTranslationTable{
  ["$ads__shengcai1"] = "天命？哈哈哈哈……",
  ["$ads__shengcai2"] = "吾乃天命之子！",
  ["ads__shengcai"] = "圣才",
  [":ads__shengcai"] = "当你使用一张牌时，你可以进行判定，然后你可以用判定牌代替之。",
  ["#ads__shengcai-invoke"] = "是否发动“圣才”进行判定？",
  ["#ads__shengcai-replace"] = "是否用判定牌代替原牌使用？",
}



ads__shengcai:addAI({
  think_skill_invoke = Util.TrueFunc,
})

return ads__shengcai
